This document has code embedded throughout. In the next section we will create a visualization using the already loaded dataset cryptodata:
import pandas as pd
# Create the Python object from R
df = r.cryptodata
# Show the new Python dataframe
df## pair symbol ask_1_price date_time_utc
## 0 BTCUSD BTC 18037.560 2020-12-12 00:00:00
## 1 ETHUSD ETH 544.422 2020-12-12 00:00:01
## 2 BTCUSD BTC 18338.710 2020-12-12 01:00:00
## 3 ETHUSD ETH 555.184 2020-12-12 01:00:01
## 4 BTCUSD BTC 18283.790 2020-12-12 02:00:00
## ... ... ... ... ...
## 5089 BTCUSD BTC 11847.080 2020-08-10 21:03:49
## 5090 BTCUSD BTC 11819.920 2020-08-10 22:03:49
## 5091 BTCUSD BTC 11804.900 2020-08-10 23:03:54
## 5092 BTCUSD BTC 10686.880 NaT
## 5093 ETHUSD ETH 357.844 NaT
##
## [5094 rows x 4 columns]
Press on w on your keyboard to make the presentation wider. Press f to fullscreen.
import numpy as np
# Create a new field based on the ask_1_price value:
df['price_percentile'] = np.where(df['ask_1_price'] > np.percentile(df['ask_1_price'], 50),
'upper 50th percentile of prices',
'lower 50th percentile of prices')
# Show modified dataframe:
df[['symbol', 'ask_1_price', 'price_percentile']]## symbol ask_1_price price_percentile
## 0 BTC 18037.560 upper 50th percentile of prices
## 1 ETH 544.422 lower 50th percentile of prices
## 2 BTC 18338.710 upper 50th percentile of prices
## 3 ETH 555.184 lower 50th percentile of prices
## 4 BTC 18283.790 upper 50th percentile of prices
## ... ... ... ...
## 5089 BTC 11847.080 upper 50th percentile of prices
## 5090 BTC 11819.920 upper 50th percentile of prices
## 5091 BTC 11804.900 upper 50th percentile of prices
## 5092 BTC 10686.880 upper 50th percentile of prices
## 5093 ETH 357.844 lower 50th percentile of prices
##
## [5094 rows x 3 columns]